/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package formularios;

import Clases.Conexion;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

/**
 *
 * @author Jrg
 */
public class MainMenu extends javax.swing.JFrame {
    
    public static String server, dataBase, user, password, pahtReportes;
    public static Conexion conexion;
    public static int IdUsuario=0;
    

    /**
     * Creates new form menuPrincipal
     */
    public MainMenu() 
    {
        initComponents();
        this.setExtendedState(JFrame.MAXIMIZED_BOTH);
        conexion= new Conexion(server, dataBase, user, password);
        this.setTitle("E D U C A N    Ver. 20042013.0837");
    }

    private boolean VerificarAcceso(int idobjeto)
    {
        int resultado=0;
        resultado = Integer.valueOf(conexion.EjecutarEscalar("select count(*) from permisos where idobjeto="+idobjeto+" and idusuario="+IdUsuario+" and debaja is null"));
        if (resultado>0)
            return true;
        return false;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new javax.swing.JDesktopPane();
        menuBar = new javax.swing.JMenuBar();
        jMenuCatalogos = new javax.swing.JMenu();
        jMenuAlumnos = new javax.swing.JMenuItem();
        jMenuMovimientos = new javax.swing.JMenu();
        jMenuInscripciones = new javax.swing.JMenuItem();
        jMenuVenta = new javax.swing.JMenuItem();
        jMenuItem1 = new javax.swing.JMenuItem();
        jMenuItem5 = new javax.swing.JMenuItem();
        jMenuItem6 = new javax.swing.JMenuItem();
        jMenuItem9 = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        jMenuItem4 = new javax.swing.JMenuItem();
        jMenuItem7 = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        jMenuItem8 = new javax.swing.JMenuItem();
        jMenuItem3 = new javax.swing.JMenuItem();
        jMenu2 = new javax.swing.JMenu();
        jMenuItem2 = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jMenuCatalogos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/folder24.png"))); // NOI18N
        jMenuCatalogos.setText("Catalogos");
        jMenuCatalogos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuCatalogosActionPerformed(evt);
            }
        });

        jMenuAlumnos.setText("Alumnos");
        jMenuAlumnos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuAlumnosActionPerformed(evt);
            }
        });
        jMenuCatalogos.add(jMenuAlumnos);

        menuBar.add(jMenuCatalogos);

        jMenuMovimientos.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/textfile24.png"))); // NOI18N
        jMenuMovimientos.setText("Movimientos");

        jMenuInscripciones.setText("Inscripcion");
        jMenuInscripciones.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuInscripcionesActionPerformed(evt);
            }
        });
        jMenuMovimientos.add(jMenuInscripciones);

        jMenuVenta.setText("Cargo Extra");
        jMenuVenta.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuVentaActionPerformed(evt);
            }
        });
        jMenuMovimientos.add(jMenuVenta);

        jMenuItem1.setText("Caja de Cobro");
        jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem1ActionPerformed(evt);
            }
        });
        jMenuMovimientos.add(jMenuItem1);

        jMenuItem5.setText("Pago de Servicios");
        jMenuItem5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem5ActionPerformed(evt);
            }
        });
        jMenuMovimientos.add(jMenuItem5);

        jMenuItem6.setText("Corte de Caja");
        jMenuItem6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem6ActionPerformed(evt);
            }
        });
        jMenuMovimientos.add(jMenuItem6);

        jMenuItem9.setText("Eliminar Inscripcion");
        jMenuItem9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem9ActionPerformed(evt);
            }
        });
        jMenuMovimientos.add(jMenuItem9);

        menuBar.add(jMenuMovimientos);

        jMenu1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/printer24.png"))); // NOI18N
        jMenu1.setText("Reportes");

        jMenuItem4.setText("Inscripciones por Grado");
        jMenuItem4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem4ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem4);

        jMenuItem7.setText("Cuentas por Cobrar");
        jMenuItem7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem7ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem7);
        jMenu1.add(jSeparator1);

        jMenuItem8.setText("Balance General");
        jMenuItem8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem8ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem8);

        jMenuItem3.setText("Estado de Resultados");
        jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem3ActionPerformed(evt);
            }
        });
        jMenu1.add(jMenuItem3);

        menuBar.add(jMenu1);

        jMenu2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/imagenes/key.png"))); // NOI18N
        jMenu2.setText("Seguridad");

        jMenuItem2.setText("Cambiar Contraseña");
        jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jMenuItem2ActionPerformed(evt);
            }
        });
        jMenu2.add(jMenuItem2);

        menuBar.add(jMenu2);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 250, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jMenuCatalogosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuCatalogosActionPerformed
        
    }//GEN-LAST:event_jMenuCatalogosActionPerformed

    
    
    private void jMenuAlumnosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuAlumnosActionPerformed
       try
       {
            if (VerificarAcceso(catalogoAlumnos.IdMenu))
            {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                catalogoAlumnos alumnos = new catalogoAlumnos(); 
                alumnos.setSize(resolucao); 
                desktopPane.add(alumnos); 
                alumnos.setLocation(0, 0); 
                alumnos.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuAlumnosActionPerformed

    private void jMenuInscripcionesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuInscripcionesActionPerformed
       try
       {
           if (VerificarAcceso(inscripciones.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize();  
                inscripciones alumnos = new inscripciones(); 
                alumnos.setSize(resolucao); 
                desktopPane.add(alumnos); 
                alumnos.setLocation(0, 0);  
                alumnos.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuInscripcionesActionPerformed

    private void jMenuVentaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuVentaActionPerformed
       try
       {
           if (VerificarAcceso(CargoExtra.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                CargoExtra venta = new CargoExtra(); 
                venta.setSize(resolucao); 
                desktopPane.add(venta); 
                venta.setLocation(0, 0); 
                venta.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuVentaActionPerformed

    private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem1ActionPerformed
       try
       {
           if (VerificarAcceso(CajaCobro.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                CajaCobro venta = new CajaCobro(); 
                venta.setSize(resolucao); 
                desktopPane.add(venta); 
                venta.setLocation(0, 0); 
                venta.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuItem1ActionPerformed

    private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem2ActionPerformed
       try
       {
         Password o = new Password(null, true);
         o.setVisible(true);
         
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuItem2ActionPerformed

    private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem3ActionPerformed
        try
        {
           if (VerificarAcceso(RptSaldoCuentas.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                RptSaldoCuentas venta = new RptSaldoCuentas(); 
                venta.setSize(resolucao); 
                desktopPane.add(venta); 
                venta.setLocation(0, 0); 
                venta.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuItem3ActionPerformed

    private void jMenuItem4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem4ActionPerformed
        try
        {
           if (VerificarAcceso(RptInscripciones.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                RptInscripciones venta = new RptInscripciones(); 
                venta.setSize(resolucao); 
                desktopPane.add(venta); 
                venta.setLocation(0, 0); 
                venta.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuItem4ActionPerformed

    private void jMenuItem5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem5ActionPerformed
        try
        {
           if (VerificarAcceso(Compras.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                Compras venta = new Compras(); 
                venta.setSize(resolucao); 
                desktopPane.add(venta); 
                venta.setLocation(0, 0); 
                venta.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuItem5ActionPerformed

    private void jMenuItem6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem6ActionPerformed
        try
        {
           if (VerificarAcceso(CorteCaja.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                CorteCaja venta = new CorteCaja(); 
                venta.setSize(resolucao); 
                desktopPane.add(venta); 
                venta.setLocation(0, 0); 
                venta.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuItem6ActionPerformed

    private void jMenuItem7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem7ActionPerformed
          try
        {
           if (VerificarAcceso(RptCuentasCobrar.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                RptCuentasCobrar venta = new RptCuentasCobrar(); 
                venta.setSize(resolucao); 
                desktopPane.add(venta); 
                venta.setLocation(0, 0); 
                venta.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuItem7ActionPerformed

    private void jMenuItem8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem8ActionPerformed
       
               
        try
        {
           if (VerificarAcceso(RptBalanceGeneral.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                RptBalanceGeneral venta = new RptBalanceGeneral(); 
                venta.setSize(resolucao); 
                desktopPane.add(venta); 
                venta.setLocation(0, 0); 
                venta.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuItem8ActionPerformed

    private void jMenuItem9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jMenuItem9ActionPerformed
        try
        {
           if (VerificarAcceso(EliminarInscripcion.IdMenu))
           {
                desktopPane.removeAll(); 
                Dimension resolucao = desktopPane.getSize(); 
                EliminarInscripcion venta = new EliminarInscripcion(); 
                venta.setSize(resolucao); 
                desktopPane.add(venta); 
                venta.setLocation(0, 0); 
                venta.setVisible(true);
            }
            else
                JOptionPane.showMessageDialog(this, "Acceso Denegado","Error",JOptionPane.ERROR_MESSAGE);
       }
       catch(Exception ex)
       {
           
       }
    }//GEN-LAST:event_jMenuItem9ActionPerformed

    
  
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(MainMenu.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new MainMenu().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenuItem jMenuAlumnos;
    private javax.swing.JMenu jMenuCatalogos;
    private javax.swing.JMenuItem jMenuInscripciones;
    private javax.swing.JMenuItem jMenuItem1;
    private javax.swing.JMenuItem jMenuItem2;
    private javax.swing.JMenuItem jMenuItem3;
    private javax.swing.JMenuItem jMenuItem4;
    private javax.swing.JMenuItem jMenuItem5;
    private javax.swing.JMenuItem jMenuItem6;
    private javax.swing.JMenuItem jMenuItem7;
    private javax.swing.JMenuItem jMenuItem8;
    private javax.swing.JMenuItem jMenuItem9;
    private javax.swing.JMenu jMenuMovimientos;
    private javax.swing.JMenuItem jMenuVenta;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JMenuBar menuBar;
    // End of variables declaration//GEN-END:variables
}
